package com.example.chapter04;

import androidx.appcompat.app.AppCompatActivity;

import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.TextView;

public class ReadStringActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_read_string);

        TextView tvReadString = findViewById(R.id.tvReadString);
        // 从strings.xml文件中读取字符串资源
        String value = getString(R.string.read_string_name);
        tvReadString.setText(value);

        TextView tvReadMeta = findViewById(R.id.tvReadMeta);
        // 从AndroidManifest.xml文件中读取meta-data元素的值
        PackageManager pm = getPackageManager();
        try {
            ActivityInfo activityInfo = pm.getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
            Bundle bundleMetaData = activityInfo.metaData;
            String mataDate1 = bundleMetaData.getString("mataDate1");
            tvReadMeta.setText(mataDate1);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        tvReadString.setText(value);
    }
}